import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'

export default defineConfig({
  plugins: [
    vue(),
    // vueDevTools(),
    ElementPlus({
      useSource: true
    }),
    AutoImport({
      resolvers:[ElementPlusResolver({importStyle:'sass'})]
    }),
    Components({
      resolvers:[ElementPlusResolver({importStyle:'sass'})]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css:{
    preprocessorOptions:{
      scss:{
        additionalData:`@use "@/assets/index.scss" as *;`
      }
    }
  },
  server: {
    host: '0.0.0.0', // 关键：监听所有网络接口
    port: 5173,      // 可选：指定端口（默认就是5173）
    open: false,      // 可选：关闭自动打开浏览器
    proxy: {
      '/ai': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/user': {  // 添加这个配置
        target: 'http://localhost:8080',
        changeOrigin: true
      }
    },
    allowedHosts: [
      '6xk356515jp5.vicp.fun', // 允许你的内网穿透域名
      // 可选：如果需要本地访问，也可以加'localhost'
    ]

  }

})
